rename *, lower

*control variables
gen black=(race==2)
gen latino=(race==3)
gen female=(gender==2)
gen edu2=1 if (edu==1 | edu==2 | edu==3)
replace edu2=2 if (edu==4 | edu==5)
replace edu2=3 if edu==6
replace edu2=4 if (edu==7)
replace edu2=5 if (edu==8 | edu==9)

gen age2=age
replace age2="19" if age=="1/9/1999"
replace age2="" if age=="10-10"
replace age2="24" if age=="24 april 2"
replace age2="20" if age=="2o"
replace age2="52" if age=="A52"
replace age2="36" if age=="36 and my last birthday was 09/14/2017"
replace age2="31" if age=="3i"
replace age2="28" if age=="28/"
replace age2="66" if age==" Sixty six" | age=="Sixty six"
destring age2, replace
replace age2=2018-age2 if age2>1000
gen pid7=1 if repd==1 & idstr==1
replace pid7=2 if repd==1 & idstr==0
replace pid7=3 if demd==0 & repd==0 & party3==2
replace pid7=4 if demd==0 & repd==0 & party3==.
replace pid7=5 if demd==0 & repd==0 & party3==1
replace  pid7=6 if demd==1 & idstr==0
replace pid7=7 if demd==1 &idstr==1

*regression analysis: belief accuracy
reg bames_w1 corr_w1 pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1  corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1  corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1  corr_w2 corr_w1##corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1  corr_w2 corr_w1##corr_w2  pid7 black latino female ideology edu2 age2 ill_att_w1

*regression analysis: interact with immigration attitudes
gen centeredillatt=ill_att_w1-4
reg bames_w1 corr_w1##c.centeredillatt black latino female ideology edu2 age2
reg bames_w2 corr_w1##c.centeredillatt  corr_w2##c.centeredillatt  pid7 black latino female ideology edu2 age2
reg bames_w3 corr_w1##c.centeredillatt  corr_w2##c.centeredillatt  pid7 black latino female ideology edu2 age2

*regression analysis: interact with party id
gen centeredpid=pid7-4
reg bames_w1 corr_w1##c.centeredpid black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##c.centeredpid corr_w2##c.centeredpid black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##c.centeredpid corr_w2##c.centeredpid black latino female ideology edu2 age2 ill_att_w1

*regression analysis: interact with Fox News
gen foxdummy=foxtv_d
replace foxdummy=1 if web1_13==1
replace foxdummy=. if finished_t3==.
reg bames_w1 corr_w1##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##foxdummy corr_w2##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##foxdummy corr_w2##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1

*regression analysis: interact with Fox News AND republican identify
reg bames_w1 corr_w1##foxdummy##repd black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##foxdummy corr_w2##foxdummy##repd black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##foxdummy corr_w2##foxdummy##repd black latino female ideology edu2 age2 ill_att_w1

*regression analysis: interact with social media 
replace smnews_d=. if finished_t3==.
reg bames_w1 corr_w1##smnews_d pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##smnews_d  corr_w2##smnews_d  pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##smnews_d  corr_w2##smnews_d  pid7 black latino female ideology edu2 age2 ill_att_w1

*regression analysis: interact with social media AND Fox news
reg bames_w1 corr_w1##smnews_d corr_w1##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##smnews_d corr_w1##foxdummy  corr_w2##smnews_d corr_w2##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##smnews_d corr_w1##foxdummy  corr_w2##smnews_d corr_w2##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1

*combined effect v. w2 only 
gen both=(corr_w1 & corr_w2)
gen w2only=(corr_w1==0 & corr_w2==1)
gen w1only=(corr_w1==1 & corr_w2==0)
reg bames_w2 both w1only w2only  pid7 black latino female ideology edu2 age2 ill_att_w1
test both=w1only
test both=w2only
reg bames_w3 both w1only w2only  pid7 black latino female ideology edu2 age2 ill_att_w1
test both=w1only
test both=w2only

*correction 1 v. correction 2
tab cond_w1, gen(cw1)
tab cond_w2, gen(cw2)

reg bames_w1 cw12 cw13 pid7 black latino female ideology edu2 age2 ill_att_w1
test cw12=cw13
reg bames_w2 cw12 cw13  cw22 cw23   pid7 black latino female ideology edu2 age2 ill_att_w1
test cw12=cw13
test cw22=cw23
reg bames_w3 cw12 cw13  cw22 cw23   pid7 black latino female ideology edu2 age2 ill_att_w1
test cw12=cw13
test cw22=cw23

*randomization check 
logit corr_w1 pid7 black latino female ideology edu2 age2 ill_att_w1
logit corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1

*attrition 
gen wave2=(recordeddate_t2!=.)
gen wave3=(recordeddate_t3!=.)
tab1 wave2 wave3

logit wave2 corr_w1 pid7 black latino female ideology edu2 age2 ill_att_w1
logit wave3 corr_w1 corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1

*regression analysis: interact with msnbc, cnn
gen msnbcdummy=msnbctv_d
replace msnbcdummy=1 if web1_7==1
replace msnbcdummy=. if finished_t3==.

gen cnndummy= cnntv_d
replace cnndummy=1 if web1_27==1
replace cnndummy=. if finished_t3==.

reg bames_w1 corr_w1##msnbcdummy pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##msnbcdummy corr_w2##msnbcdummy pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##msnbcdummy corr_w2##msnbcdummy pid7 black latino female ideology edu2 age2 ill_att_w1

reg bames_w1 corr_w1##cnndummy pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##cnndummy corr_w2##cnndummy pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##cnndummy corr_w2##cnndummy pid7 black latino female ideology edu2 age2 ill_att_w1

*regression analysis: interact with lib, con websites
replace weblib=. if finished_t3==.
replace webcon=. if finished_t3==.
replace webneu=. if finished_t3==.

reg bames_w1 corr_w1##c.weblib corr_w1##c.webcon pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##c.weblib corr_w2##c.weblib corr_w1##c.webcon corr_w2##c.webcon  pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##c.weblib corr_w2##c.weblib  corr_w1##c.webcon corr_w2##c.webcon pid7 black latino female ideology edu2 age2 ill_att_w1

*reanalyze with w2, w3 completes only
reg bames_w1 corr_w1 pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1
reg bames_w2 corr_w1  corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1
reg bames_w3 corr_w1  corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1
reg bames_w2 corr_w1  corr_w2 corr_w1##corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1
reg bames_w3 corr_w1  corr_w2 corr_w1##corr_w2  pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1

*reanalyze immigration attitudes with  w2, w3 completes only
reg bames_w1 corr_w1##c.centeredillatt black latino female ideology edu2 age2 if wave2==1 & wave3==1
reg bames_w2 corr_w1##c.centeredillatt  corr_w2##c.centeredillatt  pid7 black latino female ideology edu2 age2 if wave2==1 & wave3==1
reg bames_w3 corr_w1##c.centeredillatt  corr_w2##c.centeredillatt  pid7 black latino female ideology edu2 age2 if wave2==1 & wave3==1

*reanalyze Fox news with  w2, w3 completes only
reg bames_w1 corr_w1##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1
reg bames_w2 corr_w1##foxdummy corr_w2##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1
reg bames_w3 corr_w1##foxdummy corr_w2##foxdummy pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1

*reanalyze social media with  w2, w3 completes only
reg bames_w1 corr_w1##smnews_d pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1
reg bames_w2 corr_w1##smnews_d  corr_w2##smnews_d  pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1
reg bames_w3 corr_w1##smnews_d  corr_w2##smnews_d  pid7 black latino female ideology edu2 age2 ill_att_w1 if wave2==1 & wave3==1

*difference scores
gen dscore12=bames_w2-bames_w1 if corr_w1==0 & corr_w2==1
gen dscore13=bames_w3-bames_w1 if corr_w1==0 & corr_w2==1
ttest dscore12==0
ttest dscore13==0

*both corrections v. one correction & Figure
gen corrections=0 if both==0 & w1only==0 & w2only==0
replace corrections=1 if w1only==1
replace corrections=2 if w2only==1
replace corrections=3 if both==1
reg bames_w1 i.corrections pid7 black latino female ideology edu2 age2 ill_att_w1
estimates store Wave1
reg bames_w2 i.corrections pid7 black latino female ideology edu2 age2 ill_att_w1
estimates store Wave2
reg bames_w3 i.corrections pid7 black latino female ideology edu2 age2 ill_att_w1
estimates store Wave3
coefplot (Wave?, keep(1.corrections) lpattern(_) mstyle(x)) (Wave?, keep(2.corrections) lpattern(-)) (Wave?, keep(3.corrections)), asequation swap nooffset vertical yline(0) pstyle(p1) recast(connect)  cirecast(rcap) eqrename(Wave* = "t=") legend(label(1 "Wave 1 only") label(2 "Wave 2 only") label(3 "Both Wave 1 & 2")) noci

*reanalyze PID/libcon with dummy coding
reg bames_w1 corr_w1##c.repd corr_w1##c.demd black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##c.repd  corr_w1##c.demd corr_w2##c.repd corr_w2##c.demd  black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##c.repd  corr_w1##c.demd corr_w2##c.repd corr_w2##c.demd  black latino female ideology edu2 age2 ill_att_w1

gen centerideo=ideology-4
gen cond=(ideology>=5 & ideology<=7)
gen libd=(ideology>=1 & ideology<=3)
reg bames_w1 corr_w1##c.centerideo black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##c.centerideo corr_w2##c.centerideo pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##c.centerideo corr_w2##c.centerideo pid7 black latino female ideology edu2 age2 ill_att_w1

reg bames_w1 corr_w1##c.cond corr_w1##c.libd pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##c.cond  corr_w1##c.libd pid7 corr_w2##c.cond corr_w2##c.libd  black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##c.cond  corr_w1##c.libd pid7 corr_w2##c.cond corr_w2##c.libd  black latino female ideology edu2 age2 ill_att_w1

*reanalyze PID/libcon dropping control vars
reg bames_w1 corr_w1##c.centeredpid black latino female  edu2 age2 
reg bames_w2 corr_w1##c.centeredpid corr_w2##c.centeredpid  black latino female  edu2 age2 
reg bames_w3 corr_w1##c.centeredpid corr_w2##c.centeredpid black latino female  edu2 age2 

reg bames_w1 corr_w1##c.centerideo black latino female  edu2 age2 
reg bames_w2 corr_w1##c.centerideo corr_w2##c.centerideo  black latino female  edu2 age2 
reg bames_w3 corr_w1##c.centerideo corr_w2##c.centerideo black latino female  edu2 age2 

reg bames_w1 corr_w1##c.centeredillatt black latino female  edu2 age2 
reg bames_w2 corr_w1##c.centeredillatt corr_w2##c.centeredillatt  black latino female  edu2 age2 
reg bames_w3 corr_w1##c.centeredillatt corr_w2##c.centeredillatt black latino female  edu2 age2 

*reaanalye data with number of neutral sites visited
reg bames_w1 corr_w1##c.weblib corr_w1##c.webcon corr_w1##c.webneu pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w2 corr_w1##c.weblib corr_w2##c.weblib corr_w1##c.webcon corr_w2##c.webcon corr_w1##c.webneu corr_w2##c.webneu  pid7 black latino female ideology edu2 age2 ill_att_w1
reg bames_w3 corr_w1##c.weblib corr_w2##c.weblib  corr_w1##c.webcon corr_w2##c.webcon corr_w1##c.webneu corr_w2##c.webneu pid7 black latino female ideology edu2 age2 ill_att_w1

*individual items
gen revbeliefb_w1 = 5- beliefb_w1
gen revbeliefd_w1 = 5- beliefd_w1
gen revbeliefb_w2 = 5- beliefb_w2
gen revbeliefd_w2 = 5- beliefd_w2
gen revbeliefb_w3 = 5- beliefb_w3
gen revbeliefd_w3 = 5- beliefd_w3
for X in var beliefa_w1  revbeliefb_w1 beliefc_w1 revbeliefd_w1 beliefe_w1 belieff_w1: reg X corr_w1 pid7 black latino female ideology edu2 age2 ill_att_w1
for X in var beliefa_w2  revbeliefb_w2 beliefc_w2 revbeliefd_w2 beliefe_w2 belieff_w2: reg X corr_w1 corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1
for X in var beliefa_w3  revbeliefb_w3 beliefc_w3 revbeliefd_w3 beliefe_w3 belieff_w3: reg X corr_w1 corr_w2 pid7 black latino female ideology edu2 age2 ill_att_w1

*read times
summ control_rt_w1 corr1_rt_w1 corr2_rt_w1 control_rt_w2 corr1_rt_w2 corr2_rt_w2
